package com.zhou.controller;

import com.zhou.entity.Outbound;
import com.zhou.service.OutboundService;
import com.zhou.utis.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出库操作
 *
 * @author zhouyuyan
 */
@RestController
@RequestMapping("outbound")
public class OutboundController {
    @Autowired
    private OutboundService outboundService;

    /**
     * 出库删除
     */
    @DeleteMapping("delete")
    public Result delete(@RequestParam String id) {
        try {
            Boolean delete = outboundService.delete(id);
            return Result.success(delete);
        } catch (RuntimeException e) {
            return Result.error(e.getMessage());
        }
    }

    /**
     * 出库查询
     */
    @GetMapping("findAll")
    public Result getAll(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10") Integer pageSize) {
        try {
            List<Outbound> all = outboundService.getAll(page, pageSize);
            return Result.success(all);
        } catch (RuntimeException e) {
            return Result.error(e.getMessage());
        }
    }
    /**
     * 根据id出库查询
     */
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id") String id){
        try {
            return Result.success(outboundService.getById(id));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
}
